/**
 * @class   wosh::building::Window
 * @brief   BuildingObject representing a generic (real) window.
 *          This class provides standard Methods and properties to 
 *          control the mapped wosh::interfaces::devices::Dimmer
 *          wosh::building::Window is usually a child of wosh::building::Room
 *
 ****************************************************************************
 * @version 0.8.399 $Id: Window.h 2882 2010-08-09 11:08:30Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Building_Window_H__
 #define __WOSH_Building_Window_H__

 #include <framework/building/BuildingObject.h>

 #include <interfaces/devices/Switch.h>
 #include <interfaces/devices/Dimmer.h>


namespace wosh {
 namespace building {

 #define _Window_VERSION					0.8399

 #define _Window_METHOD_open				"open"
 #define _Window_METHOD_close				"close"

 #define _Window_METHOD_slide				"slide"
 #define _Window_METHOD_slide_up			"slide_up"
 #define _Window_METHOD_slide_down			"slide_down"

 #define _Window_EVENT_WindowStateChanged	"WindowStateChanged"


class Window : public BuildingObject
 {
	WOSH_BUILDINGOBJECT(wosh::building::Window)

	public:
		/**
		 * @brief   window states
		 */
		enum WINDOW_STATE {
			WINDOW_UNKNOWN	= 0x00,
			WINDOW_OPENED	= 0x01,
			WINDOW_CLOSED	= 0x02
		};

	public:
		/**
		 * @brief  Empty constructor.
		 */
		Window();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		Window( const Window& m ) : BuildingObject(m) { }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~Window() { }


	public:
		virtual void busMessageChild( const Message& message );

//@}
/** @name Window Interface - 
 * @{
 ******************************************************************************/
	public:
		virtual WRESULT open()							{ return mmDoOpen(NULL); }
		virtual WRESULT close()							{ return mmDoClose(NULL); }

		virtual WRESULT slide( int value, const SecurityToken* security = NULL );

		virtual WRESULT slideUp()						{ return mmDoSlideUp(NULL); }
		virtual WRESULT slideDown()						{ return mmDoSlideDown(NULL); }

	public:
		virtual std::string getMainSwitchName() const	{ return getChildByInterface(wosh::interfaces::devices::Switch::bundleType()); }

		/**
		 * @brief   Get last known window state (opened, closed, unknown)
		 * @return  current window state (enum)
		 */
		WINDOW_STATE getState() const					{ return this->state; }
		/**
		 * @brief   Get state as a literal string
		 * @return  current window state as literal string
		 */
		inline const char* getStateAsString() const		{ return getStateAsString(this->state); }
		/**
		 * @brief   Get window state as a literal string
		 * @param state [in] window state to be retrieved as literal string
		 * @return  passed window state as literal string
		 */
		static const char* getStateAsString( Window::WINDOW_STATE state );
		/**
		 * @brief   Get window state from a literal string
		 * @param state [in] window state as literal string
		 * @return  window state (as enum) associated with the argument 
		 */
		static Window::WINDOW_STATE getStateFromString( const char* state );

//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
	private:
		WRESULT mmDoOpen( const SecurityToken* security );
		WRESULT mmDoClose( const SecurityToken* security );
		WRESULT mmDoSlideUp( const SecurityToken* security );
		WRESULT mmDoSlideDown( const SecurityToken* security );
		Response* mmDoSlide( const Message* requestMessage );

	protected:
		virtual void init();
		void setState( Window::WINDOW_STATE state, bool raiseEvent = true, const SecurityToken* source_token = NULL );

	protected:
		Window::WINDOW_STATE state;		///< current state of the window


}; // class def




/**
 * @class   wosh::building::Window_StateChanged
 * @brief   Raised when door state is changed (such as open to closed).
 *
 * Internally, data is stored as wosh::List. Supports also wosh::Variant type.
 *
 * Fields are:
 *  - \c door_state [Variant::INTEGER] (always present, first item of the list)
 *  - \c previous_door_state (optional, second item of the list)
 *
 * Some getters are provided for convenience:
 * \code

 * \endcode
 *
 * @see     wosh::Fact
 * @see     wosh::building:Window
 ****************************************************************************
 * @version 0.8.399 $Id: Window.h 2882 2010-08-09 11:08:30Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
class Window_StateChanged : public wosh::Fact
 {
	WOSH_SERIALIZABLE(wosh::building::Window_StateChanged)

	public:
		/**
		 * @brief  Empty constructor.
		 */
		Window_StateChanged()
			: wosh::Fact(_Window_EVENT_WindowStateChanged) { }
		/**
		 * @brief  Constructor with initializers.
		 * @param current_window_state [in] current state of the window
		 */
		Window_StateChanged( Window::WINDOW_STATE current_window_state );
		/**
		 * @brief  Constructor with initializers.
		 * @param current_window_state [in] current state of the window
		 * @param previous_window_state [in] previous state of the window
		 */
		Window_StateChanged( Window::WINDOW_STATE current_window_state, Window::WINDOW_STATE previous_window_state );
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		Window_StateChanged( const Window_StateChanged& m )
			: wosh::Fact(m) { }
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~Window_StateChanged() { }

	public:
		/**
		 * @brief   Get window state (opened, closed, unknown)
		 * @return  current window state (enum)
		 */
		Window::WINDOW_STATE getWindowState() const;

		/**
		 * @brief   Get previous window state (opened, closed, unknown)
		 * @return  previous window state (enum)
		 */
		Window::WINDOW_STATE getPreviousWindowState() const;


}; // class def




 }; // namespace building
}; // namespace wosh

#endif //__WOSH_Building_Window_H__
